// 例子40

{
    function Point(x, y) {
        this.x = x;
        this.y = y;
    }

    Point.prototype.getX = function () {
        return this.x;
    }

    Point.prototype.getY = function () {
        return this.y;
    }

    let p = new Point(1, 2);
    console.log(p, p.getX(), p.getY()); // Point {x: 1, y: 2} 1 2
}

console.log('----------------------------------');

{
    class Point {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }

        getX() {
            return this.x;
        }

        getY() {
            return this.y;
        }
    }

    let p = new Point(1, 2);
    console.log(p, p.getX(), p.getY()); // Point {x: 1, y: 2} 1 2
}